package com.kmxd.ams.core.common.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.kmxd.ams.core.common.constant.ErrorCode;
import com.kmxd.ams.core.exception.BizException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * 档案维护类型 形成 1 整理 2 保存 3 利用 4 接收 5 鉴定 6
 *
 * @author nickbi
 */
@Getter
@AllArgsConstructor
public enum ArchManageEnum {

  /** 形成 */
  BECOMING(1, "形成"),
  /** 整理 */
  ARRANGE(2, "整理"),
  SAVE(3, "保存"),
  USE(4, "利用"),
  RECEIVE(5, "接收"),
  IDENTIFY(6, "鉴定"),
  ;
  private Integer type;
  private String desc;

  public static ArchManageEnum convert(Integer type) {
    return Arrays.stream(values())
        .filter(x -> x.type.equals(type))
        .findAny()
        .orElseThrow(() -> BizException.instance(ErrorCode.NOT_FOUND, "未找到档案状态：" + type));
  }

  public static ArchManageEnum convert(String desc) {
    return Arrays.stream(values()).filter(x -> x.desc.equals(desc)).findAny().orElse(BECOMING);
  }

  @JsonCreator
  public static ArchManageEnum getValue(Integer type) {
    return Arrays.stream(values()).filter(x -> Objects.equals(x.type, type)).findAny().orElse(null);
  }
}
